package com.grf.es.transport;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Client {

    /**
     * 获取客户端
     */
    public static TransportClient getClient() throws UnknownHostException {
        TransportClient client = null;
        Settings settings = Settings.builder().put("cluster.name","my-application")
                .put("client.transport.sniff", false).build();
        client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("hadoop101"),9300));
        //System.out.println(client.toString());
        return client;
    }

}
